<template>
  <div class="userInfo">
    <div class="el-form-box">
      <el-form
        ref="temp"
        :model="temp"
        label-width="100px"
        size="small"
        label-position="right"
      >
        <el-form-item label="通知：">
          <el-input
            v-model="temp.value"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
      </el-form>
      <!-- 修改按钮 -->
      <div style="width: 645px; float: right; text-align: center">
        <el-button
          size="small"
          type="primary"
          style="width: 100px"
          @click.native="update()"
        >修改</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getByKey, updateByKey } from '@/api/webconfig'
export default {
  data() {
    return {
      temp: {
        name: 'notice',
        value: ''
      }
    }
  },
  computed: {
    ...mapGetters([
      'token'
    ])
  },
  created() {
    this.init()
  },
  methods: {
    async init() { // 初始化
      await getByKey('notice').then((response) => {
        if (response.code === '200') {
          // 初始化通知的值
          this.temp.value = response.data
        }
      })
    },
    update() { // 修改提交
      updateByKey(this.temp).then((response) => {
        if (response.code === '200') {
          this.$notify({
            title: '提示',
            message: response.message,
            type: 'success',
            duration: 2000
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.userInfo {
  ::v-deep .el-form-box {
    width: 45%;
    margin: 20px 0;
    .logo-box {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      margin-bottom: 10px;
      .logo {
        margin-bottom: 10px;
        width: 110px;
        height: 110px;
        display: block;
        border-radius: 50%;
        background: #ffffff;
      }
    }
  }
  .changePsd {
    text-decoration: none;
    color: #0066cc;
    position: absolute;
    right: -70px;
  }
  ::v-deep .el-dialog {
    .el-dialog__header {
      border-bottom: 1px solid #ccc;
      background-color: #649bee;
      color: white !important;
    }
    .el-dialog__body {
      padding: 30px 20px 10px;
    }
  }
}
</style>
